<?php
namespace ManiaLivePlugins\MLEPP\ServerInfo\Gui\Controls;

use ManiaLib\Gui\Elements\Button;
use ManiaLive\Gui\Windowing\Controls\Pager;
use ManiaLive\PluginHandler\PluginHandler;
use ManiaLivePlugins\MLEPP\ServerInfo\ServerInfo;
use ManiaLive\Gui\Handler\GuiHandler;
use ManiaLive\DedicatedApi\Xmlrpc\Client_Gbx;
use ManiaLive\Database\Connection;
use ManiaLive\Threading\Commands\Command;
use ManiaLive\Threading\ThreadPool;
use ManiaLib\Gui\Elements\Label;

class PluginsTab extends \ManiaLive\Gui\Windowing\Controls\Tab
{
	protected $pgPlugins;
	
	function initializeComponents()
	{
		$this->btnPluginTab = new Button();
		$this->btnPluginTab->setHalign(2, 1);
		$this->btnPluginTab->setStyle(Button::CardButtonSmallWide);
		$this->btnPluginTab->setText('$000Learn more about the plugins on this server');
		$this->addComponent($this->btnPluginTab);
		
		$this->pgPlugins = new Pager();
		$this->pgPlugins->setPosition(0,5);
		$this->pgPlugins->setStretchContentX(true);
		$this->addComponent($this->pgPlugins);
	}
	
	function refreshList()
	{
		$this->pgPlugins->clearItems();
		foreach (PluginHandler::getInstance()->getLoadedPluginsList() as $plugin)
		{
			$plugin = explode('\\', $plugin);
			$author = array_shift($plugin);
			$package = implode('\\', $plugin);
			
			$item = new ListItem();
			$item->label->setText($author . ' - ' . $package);
			$this->pgPlugins->addItem($item);
		}
	}
	
	function onResize()
	{
		$this->btnPluginTab->setPosition(2, 1);
		$this->pgPlugins->setSize($this->sizeX, $this->sizeY-5);
	}
	
	function beforeDraw()
	{
		$this->btnPluginTab->setUrl('http://forum.maniaplanet.com/viewforum.php?f=47');
	}
	
}

?>